import argparse
import sys

from src.phone_gen import PhoneGenerator

USAGE = f'''
Usage: python {sys.argv[0]} [-h] [-c|p|ch|f] "string argument"
'''

DESCRIPTION = '''
Generate phone numbers.
eg. 8 999 123 1234

Here, country code can be set to 8
Prefix here can be '999'. By setting the prefix like this, only
digits in place of '123 1234' will be generated.
Eg:

8 999 123 1234
8 999 234 9999
8 999 899 1231

Chunk size changes the number of elements that are stored in memory
before being dumped to a file. Otherwise, to store a combination of 10 digit
phone numbers will require more than 10GB of RAM.
'''


def get_parser() -> argparse.ArgumentParser:
    parser = argparse.ArgumentParser(
        usage='%(prog)s [FLAG] [OPTION] "string argument"',
        description=DESCRIPTION)
    parser.add_argument(
        '-c', '--country_code', type=str, required=False, default='8',
        help=f'Specify country code')
    parser.add_argument(
        '-p', '--prefix', type=str, required=False, default='999',
        help=f'Specify prefix digits between country code and generated digits')
    parser.add_argument(
        '-ch', '--chunk_size', type=int, required=False, default=10_000,
        help=f'Specify chunk size')
    parser.add_argument(
        '-f', '--file', type=str, required=False, default='phone_numbers.txt',
        help=f'Specify output file')
    return parser


def main() -> None:
    """Start Program"""

    parser = get_parser()
    args = parser.parse_args()
    if not args:
        raise SystemExit(USAGE)

    phone_gen = PhoneGenerator(args.country_code, args.prefix)
    phone_gen.generate(args.chunk_size)
    phone_gen.save(args.file)


if __name__ == '__main__':
    main()
